package com.carlife.provider;

import com.carlife.model.MileageLog;
import com.carlife.model.OilLog;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper {
	
	private static final String DATABASE_NAME = "carlife.db";
    private static final int DATABASE_VERSION = 1;
	
	DBHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
    	// oil log table    	
        db.execSQL("CREATE TABLE "+ OilLog.TABLENAME + "("
                + OilLog.FD_OIL_NO + " INTEGER PRIMARY KEY AUTOINCREMENT, "
                + OilLog.FD_CAR_NO + " INTEGER, "
                + OilLog.FD_INPUT_TIME + " TEXT, "
                + OilLog.FD_UNIT_PRICE + " NUMERIC(10,2), "
                + OilLog.FD_OIL_TYPE + " TEXT, "
                + OilLog.FD_OIL_QUANTITY + " NUMERIC(10,2), "
                + OilLog.FD_OIL_MONEY+ " NUMERIC(10,2)"
                	+	")");
        db.execSQL("CREATE INDEX oilIndexCar ON "+ OilLog.TABLENAME + "(" + OilLog.FD_CAR_NO + ");");
        db.execSQL("CREATE INDEX oilIndexTime ON "+ OilLog.TABLENAME + "(" + OilLog.FD_INPUT_TIME + ");");
        
     // mileage log table    	
        db.execSQL("CREATE TABLE "+ MileageLog.TABLENAME + "("
                + MileageLog.FD_MILEAGE_NO + " INTEGER PRIMARY KEY AUTOINCREMENT, "
                + MileageLog.FD_CAR_NO + " INTEGER, "
                + MileageLog.FD_INPUT_TIME + " TEXT, "
                + MileageLog.FD_MILEAGE_VAlUE+ " NUMERIC(10,2)"
                	+	")");
        db.execSQL("CREATE INDEX mileageIndexCar ON "+ MileageLog.TABLENAME + "(" + MileageLog.FD_CAR_NO + ");");
        db.execSQL("CREATE INDEX mileageIndexTime ON "+ MileageLog.TABLENAME + "(" + MileageLog.FD_INPUT_TIME + ");");
    }
    
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    	// todo
    }
	

}
